//图文宝收银
var twbColletMoneyPageVm = new Vue({
    el: '#twbColletMoneyApp',
    data:function(){
      return {
          title:'收银',
          collectMoneyVisible:false,
          //收银对象
          recMoney:{},
          e:{
              payTypeEnum:[]
          },
          formLabelWidth: '120px',
          //定义变量接收原应收金额
          payableAmount:'',
      }
    } ,
    methods: {
        // 查询
        loadData: function (data) {
            var self = this;
            if(isBlank(data.orderNo)){
                alert("请选中一行进行操作!")
                return;
            }
            var orderNo=data.orderNo;
            //清空之前数据
            self.recMoney={discountRate:null,orderNo:'',memberName:'',totalMount:0,memberId:'',money:'',
                pmtGoods:0,payed:0,payName:'',depositMoney:0}
            //先根据订单号查询出订单相关信息
            //先查询当前订单是否符合操作要求
            $.get(baseURL + "twbOrder/erporder/getReceviceMoneyData/"+orderNo, function(r) {
                if(r.code==0){
                    self.e.payTypeEnum = r.payTypeEnum;
                    self.recMoney = r.recMoney;
                    self.payableAmount=r.recMoney.payableAmount;
                    self.collectMoneyVisible=true;
                }else{
                    alert(r.msg);
                }
            })
        },

        saveReceiveMoney:function () {
            var self=this;
            if(self.recMoney.money>self.payableAmount){
                alert("收款金额不能大于应收款金额");
                self.recMoney.money=self.payableAmount;
                return;
            }
            if(self.recMoney.depositMoney!=0){
                this.$confirm('是否确认押金已退还?','押金退还提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    $.ajax({
                        type: "POST",
                        url: baseURL + "twbOrder/erporder/saveReceviceMoney",
                        contentType: "application/json",
                        data: JSON.stringify(self.recMoney),
                        success: function(r){
                            if(r.code == 0){
                                alert('操作成功', function(index){
                                    self.collectMoneyVisible=false;
                                    twbOrderVm.reload();
                                });
                            }else{
                                alert(r.msg);
                            }
                        }
                    });
                }).catch(function () {
                    self.$message({
                        type: 'info',
                        message: '已取消操作'
                    })
                });
            }else{
                $.ajax({
                    type: "POST",
                    url: baseURL + "twbOrder/erporder/saveReceviceMoney",
                    contentType: "application/json",
                    data: JSON.stringify(self.recMoney),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(index){
                                self.collectMoneyVisible=false;
                                twbOrderVm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            }
        }
    }
});